#include <iostream>
#include <fstream>
#include <string>
#include <gtk/gtk.h>
#include <gtkmm.h>
#include <gtkmm/frame.h>
#include "gs-theme-window.h"
#include "NewsWidget.h"

void fill_sample_text(Gtk::TextView&);
void read_file_into_string(const std::string& filename, std::string& string_to_be_filled);


int main(int argc, char *argv[])
{
    Gtk::Main main(argc, argv);
/* before we do something with the UI we have to initialize the news machine */
    CL_News_pool* np=CL_News_pool::get_news_pool_pointer();
    np->add_source_url("http://www.spiegel.de/schlagzeilen/index.rss");


    GtkWindow* ctop_window = GTK_WINDOW(gs_theme_window_new());
    Gtk::Window* top_window = Glib::wrap(ctop_window);

    NewsWidget nd1, nd2;

    nd1.SetText("Label1","Text1");
    std::string s;
    read_file_into_string("russisch.txt", s);
    nd2.SetText("russisch.txt",s);
    Gtk::VBox vb;
    vb.pack_start(nd1);
    vb.pack_start(nd2);
    top_window->add(vb);
    top_window->show_all_children();

    Gtk::Main::run(*top_window);

    return EXIT_SUCCESS;
}

void fill_sample_text(Gtk::TextView& tv)
{
    std::string s;
    read_file_into_string("russisch.txt", s);
    Glib::ustring us(s);
    Glib::RefPtr< Gtk::TextBuffer > tb = tv.get_buffer ();
    tb->set_text(us);
}

void read_file_into_string(const std::string& fn, std::string& s)
{
    std::string line;
    std::ifstream myfile(fn.c_str());
    if (myfile.is_open())
    {
        while ( myfile.good() )
        {
            getline (myfile,line);
            s+=line;
        }
        myfile.close();
    }
    else
    {
        s="Error with file!";
    }
}

